﻿using AnesSystem.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AnesSystem.Controls
{
    /// <summary>
    /// AnesTemplate.xaml 的交互逻辑
    /// </summary>
    public partial class AnesTemplateCtrl : UserControl
    {
        public AnesTemplateCtrl()
        {
            InitializeComponent();
            _scdqsj.IsChecked = true;
            _gr.IsChecked = true;
            this.DataContext = AnesTemplateCtrlViewModel.Instance;
            this.Loaded += AnesTemplateCtrl_Loaded;

        }

        private void AnesTemplateCtrl_Loaded(object sender, RoutedEventArgs e)
        {
            AnesTemplateCtrlViewModel.Instance.ChangeDisPlayList("gr");
        }

        private void del_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBoxCommon.ShowDialog("确定要删除此条模板?", MessageBoxCommon.OKCANCLE).Value == true)
            {
                AnesTemplateCtrlViewModel.Instance.DelAnesTemplate();
            }
            else
            {
                return;
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            AnesTemplateCtrlViewModel.Instance.AddTemporaryTemplate();
            if ((bool)_scdqsj.IsChecked)
            {
                if (MessageBoxCommon.ShowDialog("确定要删除当前麻醉单数据应用此模板吗?", MessageBoxCommon.OKCANCLE).Value == true)
                {
                    AnesTemplateCtrlViewModel.Instance.ApplySelectTemplate(true);
                }
                else
                {
                    return;
                }
            }
            if ((bool)_zjsj.IsChecked)
            {
                AnesTemplateCtrlViewModel.Instance.ApplySelectTemplate(false);
            }
            DrugAndEventWindow.Instance.CloseWin(false);
        }

        private void RadioButton_Click(object sender, RoutedEventArgs e)
        {
            RadioButton radioButton = sender as RadioButton;
            string tag = radioButton.Tag.ToString();
            if (string.IsNullOrEmpty(tag))
            {
                return;
            }

            if ((bool)radioButton.IsChecked)
            {
                AnesTemplateCtrlViewModel.Instance.ChangeDisPlayList(tag);
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (MessageBoxCommon.ShowDialog("确定要撤销当前麻醉单数据吗?", MessageBoxCommon.OKCANCLE).Value == true)
            {
                AnesTemplateCtrlViewModel.Instance.SelectAnesRecordTemplate = AnesTemplateCtrlViewModel.Instance.TemporaryTemplate;
                AnesTemplateCtrlViewModel.Instance.ApplySelectTemplate(true);
                AnesTemplateCtrlViewModel.Instance.SelectAnesRecordTemplate = null;
                AnesTemplateCtrlViewModel.Instance.TemporaryTemplate = null;
            }
            else
            {
                return;
            }
            DrugAndEventWindow.Instance.CloseWin(false);
        }
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            DrugAndEventWindow.Instance.CloseWin(false);
        }
    }
}
